/********************************************************************************
 *      Copyright:  (C) 2023 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  can.h
 *    Description:  This head file head of can.c.
 *
 *        Version:  1.0.0(2023年07月11日)
 *         Author:  Ling Yun <lingyun@email.com>
 *      ChangeLog:  1, Release initial version on "2023年07月11日 21时43分06秒"
 *                 
 ********************************************************************************/

#ifndef __CAN_H__
#define __CAN_H__

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <net/if.h>
#include <pthread.h>

#define CMD_SET_CAN0_BITRATE	"ip link set can0 type can bitrate 500000 triple-sampling on"
#define CMD_CAN0_UP				"ifconfig can0 up"
#define CMD_CAN0_DOWN			"ifconfig can0 down"

#define CMD_SET_CAN1_BITRATE	"ip link set can1 type can bitrate 500000 triple-sampling on"
#define CMD_CAN1_UP				"ifconfig can1 up"
#define CMD_CAN1_DOWN			"ifconfig can1 down"

struct can_controller
{
	char	*can_name;
	int 	can_fd;
};

int can_set_controller(char *can_name);
int can_write(int can_fd,struct can_frame tx_frame);
int can_read(int can_fd,struct can_frame *rx_frame);

#endif

